package com.soundShape.mediators.menu
{
	
	import com.soundShape.events.SoundShapeEvent;
	import com.soundShape.mediators.AbstractViewMediator;
	import com.soundShape.model.ApplicationModel;
	import com.soundShape.views.menu.Menu;
	import com.soundShape.views.newEmployee.NewEmployee;
	import com.soundShape.vo.EmployeeVO;
	
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.core.UIComponent;
	import mx.effects.Move;
	import mx.effects.Rotate;
	import mx.events.FlexEvent;
	import mx.events.ValidationResultEvent;
	import mx.managers.PopUpManager;
	import mx.validators.ValidationResult;
	
	import spark.components.BorderContainer;
	import spark.components.Button;
	import spark.components.TextInput;
	import spark.utils.TextFlowUtil;
	
	
	public class MenuMediator extends AbstractViewMediator
	{
		
		public var isInitLogin:Boolean = true;	
		
		private var newCustomerInfo:String = '<span fontWeight="bold">Cick this button if you are creating a new customer.</span>' +
				'<br/><br/>Before a treatment can be associated with a customer, that customer must be added to the system.' +
				'<br/><br/>Once a customer has been added, a treatment is added next.  ' +
				'<br/><br/>Customer data can be modified in the Admin section of this application.' +
				'<br/><br/>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut ' +
				'labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ' +
				'ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in ' +
				'reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur ' +
				'sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
			
			private var treatmentInfo:String = '<span fontWeight="bold">Click this button to add a treatment to a new or returning customer.</span>' +
				'<br/><br/>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut ' +
				'labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ' +
				'ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in ' +
				'reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur ' +
				'sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
			
			private var photoInfo:String = '<span fontWeight="bold">Click this button to associate photos to a customer treatment.</span>' +
				'<br/><br/>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut ' +
				'labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ' +
				'ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in ' +
				'reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur ' +
				'sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
			
			private var comparisonInfo:String = '<span fontWeight="bold">Click this button to compare photos of treatments (before & after).</span>' +
				'<br/><br/>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut ' +
				'labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ' +
				'ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in ' +
				'reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur ' +
				'sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
			
			private var adminInfo:String = '<span fontWeight="bold">Click this button to do admin tasks</span>' +
				'<br/><br/>You must have Admin privileges to access this area of the application.' +
				'<br/><br/>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut ' +
				'labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ' +
				'ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in ' +
				'reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur ' +
				'sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
			
			private var specialDatesInfo:String = '<span fontWeight="bold">Click this button to view Customer Special Dates</span>' +
				'<br/><br/>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut ' +
				'labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ' +
				'ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in ' +
				'reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur ' +
				'sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.';
					
				public function MenuMediator()
				{
					super(Menu);
				}
				
				/**
				 * Since the AbstractViewMediator sets the view via Autowiring in Swiz,
				 * we need to create a local getter to access the underlying, expected view
				 * class type.
				 */
				public function get view():Menu
				{
					return this._view as Menu;
				}
				
				/**
				 * The <code>init()</code> method is fired off automatically by the 
				 * AbstractViewMediator when the creation complete event fires for the
				 * corresponding ViewMediator's view. This allows us to listen for events
				 * and set data bindings on the view with the confidence that our view
				 * and all of it's child views have been created and live on the stage.
				 */
				override protected function init():void
				{
					super.init();
					
					this.setViews();
					
					//soundWaves eye candy
					doSoundWaves();
					
				}
				
				override protected function setViewDataBindings():void
				{
					super.setViewDataBindings();
					
				}	
				
				override protected function setViewListeners():void
				{
					super.setViewListeners(); 
					
					this.view.btnAdmin.addEventListener(MouseEvent.CLICK, handleMenuEvent);
					this.view.btnAdmin.addEventListener(MouseEvent.MOUSE_OVER, handleMouseInfoEvent);
					this.view.btnAdmin.addEventListener(MouseEvent.MOUSE_OUT, handleMouseInfoEvent);
					
					//this.view.btnFollowUp.addEventListener(MouseEvent.CLICK, handleMenuEvent);
					//this.view.btnFreeConsultation.addEventListener(MouseEvent.CLICK, handleMenuEvent);
					this.view.btnNewCustomer.addEventListener(MouseEvent.CLICK, handleMenuEvent);
					this.view.btnNewCustomer.addEventListener(MouseEvent.MOUSE_OVER, handleMouseInfoEvent);
					this.view.btnNewCustomer.addEventListener(MouseEvent.MOUSE_OUT, handleMouseInfoEvent);
					
					this.view.btnManagePhoto.addEventListener(MouseEvent.CLICK, handleMenuEvent);
					this.view.btnManagePhoto.addEventListener(MouseEvent.MOUSE_OVER, handleMouseInfoEvent);
					this.view.btnManagePhoto.addEventListener(MouseEvent.MOUSE_OUT, handleMouseInfoEvent);
					
					//this.view.btnTransaction.addEventListener(MouseEvent.CLICK, handleMenuEvent);
					this.view.btnTreatment.addEventListener(MouseEvent.CLICK, handleMenuEvent);
					this.view.btnTreatment.addEventListener(MouseEvent.MOUSE_OVER, handleMouseInfoEvent);
					this.view.btnTreatment.addEventListener(MouseEvent.MOUSE_OUT, handleMouseInfoEvent);
					
					//this.view.btnReporting.addEventListener(MouseEvent.CLICK, handleMenuEvent);
					this.view.btnComparison.addEventListener(MouseEvent.CLICK, handleMenuEvent);
					this.view.btnComparison.addEventListener(MouseEvent.MOUSE_OVER, handleMouseInfoEvent);
					this.view.btnComparison.addEventListener(MouseEvent.MOUSE_OUT, handleMouseInfoEvent);
					
					//this.view.btnLogin.addEventListener(MouseEvent.CLICK, handleBtnLogin);
					
					
					//this.view.btnSpecialDates.addEventListener(MouseEvent.CLICK, handleMenuEvent);
					//this.view.btnSpecialDates.addEventListener(MouseEvent.MOUSE_OVER, handleMouseInfoEvent);
					//this.view.btnSpecialDates.addEventListener(MouseEvent.MOUSE_OUT, handleMouseInfoEvent);
					
				}
				
				private function setViews():void
				{
					
				}
				
				
				
				/**
				 * *******************************************************************************
				 * Handlers
				 * *******************************************************************************
				 */
				
				private function handleMenuEvent(mouseEvent:MouseEvent):void
				{
					switch(Button(mouseEvent.currentTarget).id)
					{
						case "btnAdmin":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_ADMIN_VIEW));
							break;
						
						case "btnFollowUp":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_FOLLOW_UP_VIEW));
							break;
						
						case "btnFreeConsultation":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_FREE_CONSULTATION_VIEW));
							break;
						
						case "btnNewCustomer":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_NEW_CUSTOMER_VIEW));
							break;
						
						case "btnManagePhoto":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_PHOTOS_VIEW));
							break;
						
						case "btnTransaction":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_TRANSACTIONS_VIEW));
							break;
						
						case "btnTreatment":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_TREATMENT_VIEW));
							break;
						
						case "btnReporting":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_REPORTING_VIEW));
							break;
					
						case "btnComparison":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_COMPARISON_VIEW));
							break;
						
						case "btnSpecialDates":
							this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_SPECIAL_DATES_VIEW));
							break;
						
						
					}
				}
				
				private function handleBtnLogin(mouseEvent:MouseEvent):void
				{
					this.dispatcher.dispatchEvent(new SoundShapeEvent(SoundShapeEvent.SWITCH_TO_LOGIN_VIEW));
				}
				
				
				
				private function handleMouseInfoEvent(mouseEvent:MouseEvent):void
				{
					var type:String = mouseEvent.type;
					var id:String = Button(mouseEvent.currentTarget).id;
					
					//handle the situation where upon login the user is already mouseOver the admin button
					if(isInitLogin)
					{
						isInitLogin = false;
						return;
					}
					
					switch(type)
					{
						case MouseEvent.MOUSE_OVER:
							this.view.txtArea.visible = true;
							doInfo(id);
							break;
						
						case MouseEvent.MOUSE_OUT:
							this.view.txtArea.visible = false;
							break;
					}
				}
				
				private function doInfo(id:String):void
				{
					this.view.soundShapeCircles.alpha = 0.3;
					
					switch(id)
					{
						case "btnNewCustomer":
							this.view.txtArea.textFlow = TextFlowUtil.importFromString(newCustomerInfo);
							break;
						
						case "btnTreatment":
							this.view.txtArea.textFlow = TextFlowUtil.importFromString(treatmentInfo);
							break;
						
						case "btnManagePhoto":
							this.view.txtArea.textFlow = TextFlowUtil.importFromString(photoInfo);
							break;
						
						case "btnComparison":
							this.view.txtArea.textFlow = TextFlowUtil.importFromString(comparisonInfo);
							break;
						
						case "btnAdmin":
							this.view.txtArea.textFlow = TextFlowUtil.importFromString(adminInfo);
							break;
						
						case "btnSpecialDates":
							this.view.txtArea.textFlow = TextFlowUtil.importFromString(specialDatesInfo);
							break;
					}
				}
				
				
				private function doSoundWaves():void
				{
					this.view.soundShapeCircles.alpha = 1.0;
					this.view.soundShapeCircles.doCircles(true);
				}
				
				
				/**
				 * *******************************************************************************
				 * Swiz EventHandlers
				 * *******************************************************************************
				 */
				
		}
		
	}
